package com.zking.controller;

import com.zking.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

// @RestController // 使用@RestController无法使用html页面，返回的都是JSON
@Controller
public class MyController1 {
    @RequestMapping("/")
    public String index() {
        System.out.println("访问了index……");
        return "test";
    }
    @RequestMapping("/test") // 可以访问，通过路径名寻找HTML模板
    public void test() {
        System.out.println("访问了t1……");
    }
    @RequestMapping("/t2")
    public String t2() {
        System.out.println("访问了t2……");
        return "index";
    }
    @RequestMapping("/t1")
    public String t1(Model model) {
        System.out.println("访问了t1……");
        model.addAttribute("name", "隔壁<b>老王</b>");
        model.addAttribute("style", "color: orange;");
        model.addAttribute("user", new User(1001, "蔡徐坤", "123", 1.23));
        model.addAttribute("admin", null);
        model.addAttribute("array", new String[]{"张飞", "关羽", "刘备", "诸葛"});
        model.addAttribute("list", Arrays.asList("张飞", "关羽", "刘备", "诸葛"));
        
        Map<String, Object> map = new HashMap<>();
        map.put("张飞", "张翼德");
        map.put("关羽", "关云长");
        map.put("刘备", "刘玄德");
        map.put("name", "诸葛孔明");
        model.addAttribute("map", map);
        return "test";
    }
}
